/**
 * 微擎适配列表中搜索内容
 * 适用：页面get形式搜索
 * 注意：
 *  1. 必须将所有查询内容以form的形式提交到本页
 *  2. 必须将form的id值设置为form_search
 *  3. 必须将form的method值设置为get
 */
$(function() {
    $('#form_search').on('submit', function() {
        if($(this).prop('method') != 'get') {
            return true;
        }
        var protocol = window.location.protocol;
        var host     = window.location.host;
        var pathname = window.location.pathname;
        var search   = window.location.search;
        var hash     = window.location.hash;
        var serializes = $(this).serializeArray();
        var searchObj = {};
        search.substr(1).split('&').forEach(function(item) {
            item = item.split('=');
            searchObj[item[0]] = item[1];
        });
        serializes.forEach(function(item) {
            searchObj[item.name] = item.value;
        });
        search = [];
        for(key in searchObj) {
            search.push(key + '=' + searchObj[key]);
        }
        search = '?' + search.join('&');
        var href = protocol + '//' + host + pathname + search + hash;
        location.href = href;
        return false;
    });
});

